﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Security.Principal;
using System.Xml.Linq;

namespace COM.Service
{
    [Serializable]
    public class PermissionIdentity : GenericIdentity,System.Runtime.Serialization.ISerializable,IIdentity
    {
        private bool isAuthenticated = false;

        public override string AuthenticationType
        {
            get
            {
                return string.Empty;
            }
        }

        public override bool IsAuthenticated
        {
            get
            {
                return this.isAuthenticated;
            }
        }

        public void SetIsAuthenticated(bool isAuthenticated)
        {
            this.isAuthenticated = isAuthenticated;
        }


        public PermissionIdentity(string userCode)
            : base(userCode)
        {
        }

        public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            if (context.State == System.Runtime.Serialization.StreamingContextStates.CrossAppDomain)
            {
                GenericIdentity gIdent = new GenericIdentity(this.Name, this.AuthenticationType);
                info.SetType(gIdent.GetType());

                System.Reflection.MemberInfo[] serializableMembers;
                object[] serializableValues;

                serializableMembers = System.Runtime.Serialization.FormatterServices.GetSerializableMembers(gIdent.GetType());
                serializableValues = System.Runtime.Serialization.FormatterServices.GetObjectData(gIdent, serializableMembers);

                for (int i = 0; i < serializableMembers.Length; i++)
                {
                    info.AddValue(serializableMembers[i].Name, serializableValues[i]);
                }
            }
            else
            {
                throw new InvalidOperationException("Serialization not supported");
            }
        }

    }
}


